<template>
  <d-scroll-view  @refresherrefresh="getDetail" :refresher-triggered="triggered">
    <proj-detail-layout :process-instance-id="processInstanceId" :project-number="projectNumber">
    <d-forms label-width="160rpx">
      <d-forms-item label="销售经理">
        <pm-user-select disabled :user-id="form.salesman"></pm-user-select>
      </d-forms-item>
      <d-forms-item label="招标单位" :input="form.seekTendersUnit"></d-forms-item>
      <d-forms-item label="建设单位" :input="form.constructionUnit"></d-forms-item>
      <d-forms-item label="建设单位联系人" :input="form.constructionUnitContacts"></d-forms-item>
      <d-forms-item label="建设单位电话" :input="form.constructionUnitPhone"></d-forms-item>
      <d-forms-item label="最终用户" :input="form.useUnit"></d-forms-item>
      <d-forms-item label="最终用户联系人" :input="form.useUnitContacts"></d-forms-item>
      <d-forms-item label="最终用户联系人电话" :input="form.useUnitPhone"></d-forms-item>
      <d-forms-item label="最终用户地址" :input="form.useUnitAddres"></d-forms-item>
      <d-forms-item label="招标项目名称" :input="form.seekTendersProjectName"></d-forms-item>
      <d-forms-item label="招标编号" :input="form.biddingNumber"></d-forms-item>
      <d-forms-item label="招标报名截止时间" :type="DFormInputType.DATE" :input="form.biddingRegistrationDeadline"></d-forms-item>
      <d-forms-item label="开标时间" :type="DFormInputType.DATE" :input="form.bidOpeningTime"></d-forms-item>
      <d-forms-item label="开标地址" :input="form.bidAddress"></d-forms-item>
      <d-forms-item label="招标限价" :type="DFormInputType.AMOUNT" :input="form.projectBiddingAmount"></d-forms-item>
      <d-forms-item label="投标单位数量" :input="form.biddingUnitNumber"></d-forms-item>
      <d-forms-item label="招标公告网址">
        <text>{{ form.tenderAnnouncement }}</text>
      </d-forms-item>
      <view>
        <text class="form-title-1">标书制作要求</text>
        <d-card>
          <text style="white-space: pre-wrap">{{ form.tenderPreparationRequirements }}</text>
        </d-card>
      </view>
      <d-forms-item label="结算方式" :input="form.clearingForm"></d-forms-item>
      <d-forms-item label="付款方式" :input="form.paymentTypes"></d-forms-item>
      <d-forms-item label="是否持有开票" :type="DFormInputType.DICT" :input="form.invoicingStatus" :dict-type="PM_DICT_TYPE.YES_OR_NO"></d-forms-item>
      <d-forms-item v-if="form.invoicingStatus === PmYesOrNo.NO" label="未持有开票理由" :input="form.detailedReasonsInvoicing"></d-forms-item>
      <view v-else-if="form.invoicingStatus === PmYesOrNo.YES">
        <text class="form-title-1">开票明细</text>
        <d-card>
          <pm-file-upload readonly :files="form.invoiceDetailsUrl"></pm-file-upload>
        </d-card>
      </view>
      <view>
        <text class="form-title-1">项目招标文件</text>
        <d-card>
          <pm-file-upload readonly :files="form.attachmentContentUrl"></pm-file-upload>
        </d-card>
      </view>
    </d-forms>
  </proj-detail-layout>
  </d-scroll-view>
</template>

<script setup lang="ts">
import ProjDetailLayout from "@/components/ProjDetailLayout/index.vue";
import {useProjectBidApi} from "@/api/pm/project/projectBidding";
import {getDictDataLabel, PM_DICT_TYPE} from "@/utils/pmDict";
import {formatDate} from "@dcloudio/uni-ui/lib/uni-dateformat/date-format";
import {DFormInputType, PmYesOrNo} from "@/utils/enum";

defineOptions({ name: 'ProjectBidding' })

const initForm = {
  biddingNumber: null,
  biddingRegistrationDeadline: null,
  bidOpeningTime: null,
  contractPackage: null,
  tenderPreparationRequirements: null,
  attachmentContentUrl: null,
  projectNumber: null,
  projectName: null,
  invoicingStatus: null,
  projectType: null,
  seekTendersUnit: null,
  constructionUnit: null,
  constructionUnitContacts: null,
  constructionUnitPhone: null,
  constructionUnitAddres: null,
  useUnit: null,
  useUnitContacts: null,
  useUnitPhone: null,
  useUnitAddres: null,
  seekTendersProjectName: null,
  bidAddress: null,
  invoiceDetailsUrl: null,
  projectBiddingAmount: null,
  biddingUnitNumber: null,
  tenderAnnouncement: null,
  clearingForm: null,
  paymentTypes: null,
  detailedReasonsInvoicing: null,
  storaged: null,
  result: null,
  userId: null,
  salesman: null,
  projectGrade: null,
  resultCause: null,
  processInstanceId: null,
  id: null,
}
const form = ref<ProjectBidForm>(initForm)
const triggered = ref<boolean>(false);
function getDetail() {
  if (projectNumber.value) {
    triggered.value = true;
    useProjectBidApi().getBiddingStageByProjNum(projectNumber.value).then((res) => {
      if (res.code === 0 && res.data) {
        form.value = res.data;
      }
    }).finally(() => {
      triggered.value = false;
    })
  }
}

const projectNumber = ref<string>(null);
const processInstanceId = ref<string>(null);
onLoad((query) => {
  projectNumber.value = query['project_number']
  processInstanceId.value = query['process_instance_id']
  getDetail();
})
</script>

<style scoped lang="scss">

</style>
